home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / inettime / main.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  1KB  |  68 lines

  1. /*
  2.  * This program is an example using the DARPA "Daytime Protocol"
  3.  * (see RFC 867 for the details) and the DARPA "Time Protocol"
  4.  * (see RFC 868 for the details).
  5.  *
  6.  * BSD systems provide a server for both of these services,
  7.  * using either UDP/IP or TCP/IP for each service.
  8.  * These services are provided by the "inetd" daemon under 4.3BSD.
  9.  *
  10.  *    inettime  [ -t ]  [ -u ]  hostname ...
  11.  *
  12.  * The -t option says use TCP, and the -u option says use UDP.
  13.  * If neither option is specified, both TCP and UDP are used.
  14.  */
  15.  
  16. #include    <stdio.h>
  17.  
  18. #define    MAXHOSTNAMELEN    64
  19.  
  20. char    hostname[MAXHOSTNAMELEN];
  21. char    *pname;
  22.  
  23. main(argc, argv)
  24. int   argc;
  25. char  **argv;
  26. {
  27.     int    dotcp, doudp;
  28.     char    *s;
  29.  
  30.     pname = argv[0];
  31.     dotcp = doudp = 0;
  32.  
  33.     while (--argc > 0 && (*++argv)[0] == '-')
  34.         for (s = argv[0]+1; *s != '\0'; s++)
  35.             switch (*s) {
  36.  
  37.             case 't':
  38.                 dotcp = 1;
  39.                 break;
  40.  
  41.             case 'u':
  42.                 doudp = 1;
  43.                 break;
  44.  
  45.             default:
  46.                 err_quit("unknown command line option: %c", *s);
  47.             }
  48.  
  49.     if (dotcp == 0 && doudp == 0)
  50.         dotcp = doudp = 1;        /* default */
  51.  
  52.     while (argc-- > 0) {
  53.         strcpy(hostname, *(argv++));
  54.  
  55.         if (dotcp) {
  56.             tcp_daytime(hostname);
  57.             tcp_time(hostname);
  58.         }
  59.  
  60.         if (doudp) {
  61.             udp_daytime(hostname);
  62.             udp_time(hostname);
  63.         }
  64.     }
  65.  
  66.     exit(0);
  67. }
  68.